package com.bluesky.jwf.component.validator;

import com.bluesky.javawebbrowser.domain.html.tags.Tag;
import com.bluesky.jwf.ComponentFactory;
import com.bluesky.jwf.component.Component;

public class Validator extends Component {

	protected Component target;
	protected Tag messageTag;

	protected String message;

	/**
	 * last validation result
	 */
	protected boolean result = true;

	public Validator() {

	}

	@Override
	public void init(String html) {
		super.init(html);

		messageTag = loadByJwfClass("message");

	}

	public void validate() {
		setResult(true);

	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;

		messageTag.setBodyAndParse(message);

	}

	public boolean getResult() {
		return result;
	}

	public void setResult(boolean result) {
		this.result = result;

		if (!result)
			messageTag.setStyleAttribute("color", "red");
		else
		{
			messageTag.removeStyleAttribute("color");
		
			//boolean b = messageTag.getStyleAttributes().isEmpty();
			//System.out.println(b);
			//messageTag.setStyleAttribute("color", "black");
		}
	}

	public Component getTarget() {
		return target;
	}

	public void setTarget(Component target) {
		this.target = target;
	}

	
	
}
